package com.woniuxy.service.impl;

import com.woniuxy.Exception.serviceException;
import com.woniuxy.dao.NurseDao;
import com.woniuxy.entity.Nurse;
import com.woniuxy.entity.PageBean;
import com.woniuxy.entity.Prescription;
import com.woniuxy.service.NurseService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.exceptions.PersistenceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.logging.Logger;

@Slf4j
@Service
public class NurseServiceImpl implements NurseService {
  @Autowired
    NurseDao nurseDao;
    @Override
    public void addNurse(Nurse nurse) {
nurseDao.insertNurse(nurse);
        log.info("添加成功");
    }

    @Override
    public void removeNurse(int nurseId) {

   nurseDao.deleteNurseById(nurseId);
        log.info("删除成功");
    }

    @Override
    public void upNurse(Nurse nurse) {
nurseDao.updateNurse(nurse);
log.info("修改成功");
    }

    @Override
    public PageBean<Nurse> getAllNurse(Nurse nurse, int pageIndex, int pageSize) {
try {
    PageBean<Nurse> pageBean = new PageBean<>();
//页码
    pageBean.setPageIndex(pageIndex);
//页大小
    pageBean.setPageSize(pageSize);
//获取总条数
    int count = nurseDao.selectAllNurseCount(nurse);

    pageBean.setTotalRecord(count);
    pageBean.setBeanList(nurseDao.selectAllNurse(nurse, pageIndex, pageSize));


    return pageBean;
} catch(PersistenceException e){

    throw new serviceException("系统维护中");
}

}
}
